package com.upb.webserver.common.enums;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
public enum OrderStatusEnum {
    APPLYING_BY_DEVELOPER(0, "申请中"),
    WAIT_FOR_MANAGER_HANDLE(1, "待管理员处理"),
    HANDLING_BY_MANAGER(2, "管理员处理中（创链中、创应用中）"),
    HANDLE_FAIL_BY_MANAGER(3, "管理员处理失败（创链失败）"),
    HANDLE_SUCCESS_BY_MANAGER(4, "管理员处理成功（链或应用正常启动）"),
    PERMIT_BY_MANAGER(5, "管理员同意正常结单"),
    REJECTED_BY_MANAGER(6, "工单被管理员退回");

    private byte value;
    private String description;


    OrderStatusEnum(int value, String description) {
        this.value = (byte) value;
        this.description = description;
    }

    public byte getValue() {
        return this.value;
    }

    /**
     * @param value
     * @return
     */
    public static OrderStatusEnum getByValue(byte value) {
        for (OrderStatusEnum res : OrderStatusEnum.values()) {
            if (res.value == value) {
                return res;
            }
        }
        return null;
    }


    /**
     * @return
     */
    public ChainOrAppStatusEnum convertToChainOrAppStatusEnum() {
        switch (this) {
            case APPLYING_BY_DEVELOPER:
                return ChainOrAppStatusEnum.APPLYING_BY_DEVELOPER;
            case WAIT_FOR_MANAGER_HANDLE:
                return ChainOrAppStatusEnum.WAIT_FOR_MANAGER_HANDLE;
            case HANDLING_BY_MANAGER:
                return ChainOrAppStatusEnum.ALREADY_TO_INITIALIZED;
            case PERMIT_BY_MANAGER:
            case HANDLE_SUCCESS_BY_MANAGER:
                return ChainOrAppStatusEnum.RUNNING;
            case REJECTED_BY_MANAGER:
                return ChainOrAppStatusEnum.REJECTED_BY_MANAGER;
            case HANDLE_FAIL_BY_MANAGER:
                return ChainOrAppStatusEnum.DEPLOY_FAIL;
        }
        log.error("fail exec method[convertToOrderStatusEnum]. not config status:{} desc:{}", this.getValue(), this.getDescription());
        return null;
    }

}
